package com.shop.cereshop.app.param.shop;

import com.shop.cereshop.app.domain.shop.QueryShopDTO;
import com.shop.cereshop.commons.domain.common.PageParam;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;

/**
 * @description:  推荐店铺列表请求参数
 * @author zdd
 * @date 2025/10/21 22:10
 * @version 1.0
 */
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "SuggestShopParam", description = "推荐店铺列表请求参数")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class SuggestShopParam extends PageParam implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "店铺类型：1-同城服务(到店用) 2-线上商城(电商购) 3-同城配送(同城送)")
    private Integer shopType;

    @ApiModelProperty(value = "城市编码")
//    @NotBlank(message = "cityCode不能为空")
    private String cityCode;

    @ApiModelProperty(value = "排序类型：1-最新上架 2-销量优先 3-好评优先")
    private Integer sortType;

    @ApiModelProperty(value = "距离（米）")
    private Double distance;

    @ApiModelProperty(value = "用户点位(经度,纬度，如 114.293589,30.597117)")
    private String location;


    public QueryShopDTO toQueryShopDTO(){
        QueryShopDTO dto = new QueryShopDTO();
        dto.setShopType(this.shopType);
        dto.setCityCode(this.cityCode);
        dto.setSortType(this.sortType);
        dto.setDistance(this.distance);
        dto.setLocationRegexp("^-?[0-9]+\\\\.?[0-9]*,-?[0-9]+\\\\.?[0-9]*$");
        if (StringUtils.isNotBlank(this.location) && this.location.contains(",")) {
            String[] locationArr = this.location.split(",");
            if (locationArr.length == 2) {
                dto.setLongitude(Double.parseDouble(locationArr[0]));
                dto.setLatitude(Double.parseDouble(locationArr[1]));
            }
        }
        dto.setPage(this.getPage());
        dto.setPageSize(this.getPageSize());
        return dto;
    }

}
